/**################################################################################################**   
# Copyright (c)  2008  Carlos Galindo.   
# Permission is granted to copy, distribute and/or modify this document   
# under the terms of the GNU Free Documentation License, Version 1.2   
# or any later version published by the Free Software Foundation;   
# Provided 'as is' with no warranties, nor shall the autor be responsible for any mis-use of the same.     
# A copy of the license is included in the section entitled 'GNU Free Documentation License'.   
#   
#   CJAX FRAMEWORK 3.0.0RC2                $     
#   ajax made easy with cjax                    
#   -- DO NOT REMOVE THIS --                    
#   -- AUTHOR COPYRIGHT MUST REMAIN INTACT -   
#   CJAX FRAMEWORK  3.0.0RC2               $     
#   Written by: Carlos Galindo                  
#   Website: www.cjax.net                     $      
#   Email: cjxxi@msn.com    
#   Date: 2/12/2007                           $     
#   File Last Changed:  03/24/2009            $     
**####################################################################################################*/   

var CJAX = new CJAX_FRAMEWORK();	
	CJAX.initiate();
	
function CJAX_FRAMEWORK() {
	this.name		=	'cjax';
	this.debug = false;
	var CJAX_CACHE = [];
	var _FUNCTION;
	var __base__;
	var parameters;
	this.COMPONENTS = [];
	this.EXTENSIONS = [];
	this.vars = [];
	this.message_id = 0;
	this.left_delimeter = "<";
	this.right_delimeter = ">";
	this.messages = [];
	
		
    this.AddEventTo     =       function( buffer ) 
    {
    	var array = CJAX.xml('array',buffer);
    	var element = CJAX.xml('element_event',buffer);
    	var alt_element = CJAX.xml('alt_element',buffer)
    	
        if(element == 'window') {
            try {
                    CJAX.addEvent(window,evento,  eval( method )  );
                }catch( e ){/*alert( e );*/}
                return true;
        }
    	if( !element && !alt_element){
    		alert('no element:'+buffer);
    		return;
    	}
    	if(array) {
    	    array = CJAX.decode(array,"sqt");
       		array = CJAX.decode(array,"sed");
        	var arr = CJAX.unserialize(array);
        	var alt = e = null;
        	interval = 150;
        	interval_result = null;
        	var counter = 0;
        	for(x in arr) {
        		if(alt = CJAX.xml('alt_element',arr[x])) {
        			e = CJAX.xml('alt_event',arr[x]);
        			
        			if(e && !CJAX.$(alt)) {
        				interval_result = setInterval( function() {
	        				if( CJAX.$( alt ) ) {
	        					CJAX.set.event( CJAX.$( alt ) , e ,arr[x]);
	        					clearInterval(interval_result);
	        				} else {
	        					counter++;
	        					if(counter > (interval * 10)) {
	        						clearInterval(interval_result);
	        					}
	        				}
	        			},interval);
        			} else {
        				CJAX.set.event(CJAX.$( alt ), e ,arr[x]);
        			}
        		} else {
        			CJAX.set.event(CJAX.$( element ), x ,arr[x]);
        		}
        	}
    	} else {
 	        var method = CJAX.xml('event_method',buffer);
	        var evento = CJAX.xml('event_action',buffer);
	        if( !evento ) evento = 'load';	
    	    if(CJAX.xml('observe', buffer)) {
    	    	CJAX.$( element )
    			var observe = setInterval(
    			function() {
    				if(CJAX.$( element )) {
    					//	CJAX.EventCache.flush(event_id);
    					
    	   				event_id = CJAX.set.event(CJAX.$( element ),evento,method);
    					clearInterval(observe);
    				} 
    			},400);
    		} else {
	       	 	CJAX.set.event(CJAX.$( element ),evento,method);
	        }
    	}
    }

    this.addEvent           =           function( obj, type, fn) 
    {
    	if(!CJAX.defined(id)) {
    		var id = null;
    	}
        if (obj.addEventListener) {
            try {
                    obj.addEventListener( type, fn, false );
                }
                catch( e ){alert( e );}
            return CJAX.EventCache.add(obj, type, fn);
        } else if (obj.attachEvent) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
            obj.attachEvent( "on"+type, obj[type+fn] );
            CJAX.EventCache.add(obj, type, fn);
        } else {
            obj["on"+type] = obj["e"+type+fn];
        }
    }
    
    var listEvents = [];
    this.EventCache         =           function(){
        return {
            listEvents : listEvents,
            add : function(node, sEventName, fHandler){
                return listEvents.push( arguments );
            },
            flush : function( event_id ){
                if(typeof event_id =='undefined') var event_id;
                var i, item;
                for(i = listEvents.length - 1; i >= 0; i = i - 1){
                    item = listEvents[i];
                    if(item[0].removeEventListener){
                        item[0].removeEventListener(item[1], item[2], item[3]);
                    };
                    if(item[1].substring(0, 2) != "on"){
                        item[1] = "on" + item[1];
                    };
                    if(item[0].detachEvent){
                        //item[0].detachEvent(item[1], item[2]);
                        item[0].detachEvent(item[1], item[0][eventtype+item[2]]);
                    };
                    item[0][item[1]] = null;
                };
            }
        };
    }();
	
	
	this.get		=		function() {
		return {
			extension: function(path) {
			var pos = CJAX.strrpos(path,'.');
			if(!pos) {
				return '';
			}
				return CJAX.substr(path,pos,path.len());
			}
			,
			dirname : function (path,loops) {
				var self = CJAX.get.script.self();
				if(!self || !path) {
					return false;
				}
				path.match(/(.*)[\/\\]/)[1];
				if( loops ){
					for(var i = 0; i < loops-1; i++){
					try{
						path = path.match( /(.*)[\/\\]/ )[1];
						}
						catch( e ) {}
					}
				}
			    return path;
			 }
			,basepath : function () {
				var path = CJAX.get.script.self();
				path = CJAX.get.dirname(path,3);
				var len = path.substr(path.length - 4);
				if(len=='core') {
				//if cjax is called from a parent-child file
					path = CJAX.get.dirname(path,2);
				}
				//http://127.0.0.1/phpmember/cjax/core
				return path;
			},
			basename : function(path, suffix) {
			    var b = path.replace(/^.*[\/\\]/g, '');
			    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
			        b = b.substr(0, b.length-suffix.length);
			    }
			    return b;
			}
			,scripts : {
				src : function () {
						var paths = [];
						var script;
						var scripts = CJAX.elem_docs( 'script' );
						for( var i = 0; i < scripts.length; i++ ){
							script = scripts[i];
							if(script.src) paths[i] = script.src;
						}
						return paths;
					}
			},
			script : {
				self: function () {
						var script;
						var scripts = CJAX.elem_docs( 'script' );
						for( var i = 0; i < scripts.length; i++ ){
							script = scripts[i];
							if(script.id='cjax_lib') return script.src;
						}
						return paths;
				}
			},
			value : function(elem,verbose) {
			
			
			
				var type = (typeof elem);
				if( typeof verbose == 'undefined') { verbose = true; }
				if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
				return elem.value;
			},
			 position : function(elem,verbose) {
				var type = (typeof elem);
				if( typeof verbose == 'undefined') { verbose = true; }
				if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
				var pos = [];
				var  curleft = curtop = curright = curdown = 0;
				if ( elem.offsetParent ) {
					do {
							curleft += elem.offsetLeft;
							curtop += elem.offsetTop;
					} while (elem = elem.offsetParent);		
					pos[0] = curtop;
					pos[4] = curleft;
					
					return pos;
				}
			},
			property : {
				readonly: function(elem,verbose) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					return elem.readOnly;
				}
				,
				enabled: function(elem,verbose) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					return (elem.disabled)? false : true;
				},
				disabled: function(elem,verbose) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					return elem.disabled;
				},style : function(elem,verbose) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					return elem.style;
				}
				, parent : function(elem,verbose) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					return elem.parentNode;
				}, position : function(elem,verbose) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					var pos = [];
					var  curleft = curtop = curright = curdown = 0;
					if ( elem.offsetParent ) {
						do {
								curleft += elem.offsetLeft;
								curtop += elem.offsetTop;
						} while (elem = elem.offsetParent);		
						pos[0] = curleft;
						pos[4] = curtop;
						return pos;
					}
				}
				},parent : function(elem,type_of) {
					var type = (typeof elem);
					if( typeof verbose == 'undefined') { verbose = true; }
					if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
					var parent;
					if(CJAX.get.isType(elem.parentNode,type_of)) {
						return elem.parentNode;
					} else {
						var giveup = 30;
						var i = 0;
						while(!CJAX.get.isType(elem,type_of) && !elem) {
							i++;
							parent = 	elem.parentNode;
							elem = elem.parentNode;
							if(i >= giveup) {
								break;
							}
						}
						return parent;
					}
				},
			isType: function(element,element_type) {
				if(!element)  return false;
				var type = (typeof element);
				if(element_type=='table') {
					if(element.rows.length) {
						return true;
					}
				}
				if( type.indexOf( element_type ) == -1) { return false }
				return true;
			}
			,
			properties : function(elem,verbose) {
				var type = (typeof elem);
				if( typeof verbose == 'undefined') { verbose = true; }
				if( type.indexOf( 'object' ) == -1) {var elem = CJAX.$(elem,verbose);}
				var p = [];
				p['id'] = elem.id;
				p['name'] = elem.name;
				p['readonly'] = elem.readOnly;
				p['disabled'] = CJAX.elements.disabled(elem,false);
				p['enabled'] = p['disabled']? false: true;
				p['value'] = elem.value;
				return p;
			},
			cache : function( key ) {
				return CJAX.cache.get( key );
			}
		}
	}();
	
	this.unset         =           function(){      
		return {
			timeout:function(id) {
                clearTimeout(id);
			}
		
		}
	}();
	
	
	this.set				=			function() {
		return {
			value : function(elem,value,verbose){
				if( !elem ) return false;
				var elem = CJAX.is_element(elem,verbose);
				if( elem ) { elem.value = value; return true; }
				return false;
			}
			,type: function(elem,new_type,verbose){
				if( !elem ) return false;
				var elem = CJAX.is_element(elem,verbose);
				if( elem ) { elem.type = new_type; return true;}
				return false;
			}
			,name : function(elem,new_name,verbose){
				if( !elem ) return false;
				var elem = CJAX.is_element(elem,verbose);
				if( elem ) {elem.name = new_name; return true;}
				return false;
			},style : function(elem,new_name,verbose){
				/**
				*TODO
				**/
			}
			,property: {
					focus : 
					function(elem,verbose){
						if( !elem ) return false;
						var elem = CJAX.is_element(elem,verbose);
						if(elem && window.focus())
						{
							elem.focus();
							return true;
						}
						return false;
					}
			}
			,event : function(element,event,method,cache_id){
				if( !element ) return false;
				var element = CJAX.is_element( element );
				var f = method.toString();
				f = f.substr(0,f.indexOf('('));
				f = f.rtrim();
				if(f =='function') {
				    CJAX.addEvent(element,event,eval(method));
				} else {
				    if(element.href) {
				    	
				        element.href= 'javascript:void(0)';
				        element.onclick = function() {return false;}
				    } else {
				        if(element.type && (element.type == 'checkbox' || element.type=='radio')) {
			                element.onclick = function() {return true;}
			            } else {
			                element.onclick = function() {return false;}
			            }
		            }
					return CJAX.addEvent(element,event,function() {
						method = method.replace(/_do_/g,"do");
						method =  method.replace(/\n/g,"");
						
						if(CJAX.is_xml(method)) {
							method = "<cjax>"+method+"</cjax>";
							CJAX.source = method;
							CJAX.process(method);
						} else {
							eval(method);
						}
						
					},((typeof cache_id !='undefined')? cache_id: null));
				}
			} 
			,center : function(obj) { 
			    var element = CJAX.is_element(obj);
			    element.style.position ='absolute';
		        var ctop = (screen.height /4);
		        with (element.style) {
			        top = CJAX.getY()+ctop+'px';
			        left = '50%'; 
			        marginLeft = '-'+((element.offsetWidth / 2)-18)+'px';
		        }
               return element;
			}
		}
	}();
	
	this._value	=	function(buffer,type) {
		var fpoint,lpoint,r,presentation,v;
		fpoint = buffer.indexOf(CJAX.left_delimeter);
		if(fpoint !=-1) {
			lpoint = buffer.indexOf(CJAX.right_delimeter);
			presentation = buffer.substring(fpoint,lpoint+1);
			r = buffer.substring(fpoint+1,lpoint);
			r = CJAX.$(r);
			if(r) {
				if(typeof type !='undefined') {
					v = eval(r+"."+type);
				} else {
					v = r.value;
				}
				buffer = buffer.replace(presentation,v);
				return buffer;
			}
			
		}
		return buffer;
	}
	
	/*
	# this function allow to call plugins from within javascript
	#*/
	this.plugin				=		function(method) {
		var params = '';
		var cmd = '';
		if(CJAX.is_xml(method)) {
			 var param1 = CJAX.xml('param1',method);
			 var param2 = CJAX.xml('param2',method);
			 var param3 = CJAX.xml('param3',method);
			 if(param1) {
			 	params  = params+"params[]="+param1;
			 }
			 if(param2) {
			 	params  = params+"&params[]="+param2;
			 }
			 if(param3) {
			 	params  = params+"&params[]="+param3;
			 }
			 var method = CJAX.xml('name',method);	 
			 action = "method="+method+"&";
			  cmd = params;
			 params = '<params>'+params+'</params>';
			 
			
		} else { 
			if(arguments.length)  {
				for( var i = 0; i < arguments.length; i++ ) {
					params = params+'<param>'+arguments[i]+'</param>';
					cmd = cmd+'params[]'+'='+arguments[i];
					if(i+1 != arguments.length) {
						cmd = cmd+'&';
					}
				} 
				action = "method="+method+"&";
				params = '<params>'+params+'</params>';
			}
		}
		CJAX.source = "<cjax><do>"+method+"</do>"+params+"<extension>plugin.class</extension><ctype>extension_system</ctype><settings><method>"+method+"</method><base>__base__/core/classes/</base></settings><ext>.php?"+action+cmd+"</ext></cjax>";
		CJAX.process(CJAX.source);
		CJAX.source='';
	}
	
	this.onStartEvents		=		function() 
	{
		__base__ = CJAX.vars['base'] = CJAX.get.basepath();
		CJAX.vars['loaded'] = [];
		__construct();
	}
	
	/**
	* Display a message in the middle of the screen
	*/
	this.message		=		function( buffer , time) 
	{
		var element = (CJAX.xml('element',buffer)?CJAX.xml('element',buffer):'cjax_message');
		var div = CJAX.create.div(element);
		if(!CJAX.is_xml(buffer)) {
			data = buffer;
		} else {
			var data = CJAX.xml('data',buffer);
			data = CJAX.decode( data );
		}
		if(!CJAX.defined(time)) {
		  var time = CJAX.xml('time',buffer);
		}
		div.innerHTML = data;
		CJAX.set.center(div);
		div.style.zIndex = '90';
		//time in seconds to remove the message from the screen
		var seconds = CJAX.xml('seconds',buffer);
		if( time > 0 && (seconds > time) || (!seconds && time)){
			if(CJAX.message_id) {
				clearTimeout(CJAX.message_id);
		    }
			CJAX.messages[CJAX.message_id]= setTimeout(function(){
				CJAX.is_element(element,false).innerHTML='';
			}
			,time*1000);
		}
	}
	
	this.to_cursor		=		function(element,myValue)
	{
		element = CJAX.is_element(element);
		var current_pos = element.scrollTop;
		//IE support
		if (document.selection) {
			element.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}
		else if (element.selectionStart || element.selectionStart == '0') {
			//alert(element.scrollTop);
			var startPos = element.selectionStart;
			var endPos = element.selectionEnd;
			element.value = element.value.substring(0, startPos)
			+ myValue
			+ element.value.substring(endPos, element.value.length);
			} else {
				element.value += myValue;
		}
		try {
		element.scrollTop = current_pos;
		}catch(e) {}
		//alert(element.viewNode);
	}
	
	this.striptags 		=		function( data ) {
		var html = data.replace(/(<([^>]+)>)/ig,"");
		html = html.replace(/(&([^\s].*);)+/ig,""); 
		return html;
	}
	
	this.rand		=		function (min, max ){
	    if( max ) {
	        return Math.floor(Math.random() * (max - min + 1)) + min;
	    } else {
	        return Math.floor(Math.random() * (min + 1));
	    }

	}
	
	this.echo		=		function ( ) {
	    var doc_elem = document.createDocumentFragment();
	    for( i = 0; i < CJAX.echo.arguments.length; i++ ) {
	        if( doc_elem.body && doc_elem.body.innerHTML ) {
	            doc_elem.body.innerHTML = doc_elem.body.innerHTML + echo.arguments[i];
	        } else if (doc_elem.write) {
	            doc_elem.write( echo.arguments[i] );
	        }
	    }
	    return null;
	}

	this.create		=		function() {
		return{
			script: function( path ) {
				if(!CJAX.script.loaded( path )) {
					return CJAX.script.load( path );
				}
			},
			div:function(id,parent,append) {
				if(typeof append == 'undefined') var append = true;
				var element = CJAX.is_element(id,false);
				if(!parent || parent == 'body') {
					parent = CJAX.elem_docs( 'body' )[0];
				} else {
					if( !parent ) parent = CJAX.is_element(parent,false);
				}
				if( !parent )return false;
				if(element && parent){	
					if( append ) {
						parent.appendChild( element );
					} else {
						CJAX.elem_docs( 'body' )[0].appendChild( element );
					}
					return element;
				}
				var div = document.createElement( 'div' );
				div.setAttribute('id',id);
				 
				if( append ) { 
					parent.appendChild( div );
				} else {
					CJAX.elem_docs( 'body' )[0].appendChild( div );
				}
				return div;
			},
			select: function(id,parent) {
				var select;
				if(select = CJAX.is_element(id)) {
					return select;
				}
				select = document.createElement('select');
				select.name = id;
				select.id = id;
				
				return select;	
			},
			span:function(id,parent) {
				var element = CJAX.is_element( id );
				if(!parent || parent == 'body') parent = CJAX.elem_docs( 'body' );
				else parent = CJAX.is_element(parent,false);
				if( !parent )return false;
				if(element && parent)
				{
					parent.appendChild( element );
					return element;
				}
				var div = document.createElement( 'span' );
				div.setAttribute('id',id);
				parent.appendChild( div );
				return div;
			},
			textbox:function(id,parent,label) {
				//make sure the element doesnt exist before it tries to create it
				var elem = elem_doc(id,false);
				if( elem ){return elem;}
				var parent = elem_doc( parent );
				if( label ){
					var olabel = document.createElement( 'LABEL' );
					olabel.setAttribute('id','label_'+id); 
					olabel.setAttribute('for',id); 
					olabel.innerHTML = label;
					parent.appendChild( olabel ); 
				}
				var textbox = document.createElement( 'INPUT' );
				textbox.setAttribute('type','text');
				textbox.setAttribute('id',id);
				parent.appendChild( textbox ); 
				return textbox;
			},
			frame:function(id) {
				if(!id) {
					var id = 'cjax_iframe';
				}
				var frame = CJAX.$(id,false);
				if(!frame) {
					frame = document.createElement("IFRAME");
					frame.setAttribute('id',id);
					frame.setAttribute('name',id);
					frame.setAttribute("src", "");
					//document.body.appendChild(frame);
				}
				return frame;
			},
			form:function(id) {
				if(!id) {
					var id = 'cjax_form';
				}
				var form = CJAX.$(id);
				if(!form) {
					form = document.createElement("FORM");
					form.method = "POST";
					form.encoding = "multipart/form-data";
					form.id = id;
					form.name = id;
				}
				return form;	
			}
	}
	}();
	
	this.click		=		function( buffer ) {
		var item = CJAX.xml('element',buffer)
		elem = CJAX.$( item ); 
		if( elem )elem.click();
	}
		
	this.textbox		=		function( buffer ) {
	  	var id = CJAX.xml('element',buffer);
	  	var parent = CJAX.xml('parent',buffer); 
	  	var label = CJAX.xml('label',buffer);
	  	var textbox = CJAX.create.textbox(id,parent,label);
	 	if( textbox ) {
		  var value = CJAX.xml('value',buffer);
		  var _class = CJAX.xml('class',buffer);  
	 	}
	}
	 
	this.strrpos		=		function ( haystack, needle, offset) {
	    var i = haystack.lastIndexOf( needle, offset );
	    return i >= 0 ? i : false;
	}

	this.substr		=		function ( f_string, f_start, f_length ) {
	    if(f_start < 0) {
	        f_start += f_string.length;
	    }
	
	    if(f_length == undefined) {
	        f_length = f_string.length;
	    } else if(f_length < 0){
	        f_length += f_string.length;
	    } else {
	        f_length += f_start;
	    }
	
	    if(f_length < f_start) {
	        f_length = f_start;
	    }
	
	    return f_string.substring(f_start, f_length);
	}
	
	this.empty		=		function ( mixed_var ) {
   		return ( mixed_var === "" || mixed_var === 0   || mixed_var === "0" || mixed_var === null  || mixed_var === false  ||  ( is_array(mixed_var) && mixed_var.length === 0 ) );
	}
	
	this.ltrim         =       function(string,replace)
	{
	   if(!replace) {
	       var replace = " ";
	   }
	   return string.replace(/replace/ig,string);
	}
	
	this.select				=		function(buffer)
	{
		var array = CJAX.xml('array',buffer);
		if(array) {
    	    array = CJAX.decode(array,"sqt");
       		array = CJAX.decode(array,"sed");
        	var arr = CJAX.unserialize(array);
        	var parent = CJAX.xml('parent',buffer);
        	var id = CJAX.xml('id',buffer);
        	var select = CJAX.create.select(id);
        
        	for(x in arr) {
	        	var option = document.createElement('OPTION');
				option.text = arr[x];
				option.value = x;
				select.options.add(option);
        	}
        	if(parent) {
        		parent = CJAX.$(parent);
        		parent.appendChild(select);
        	} else {
        		parent = CJAX.elem_docs('body')[0];
        		parent.appendChild(select);
        	}
        	return select;
		}
	}

	this.initiate			=			function() {
		var cjax_css = this.addCSSRule('.'+this.name,this.name);
		if(cjax_css) {
			cjax_css.style.position = 'absolute';
			cjax_css.style.visibility = 'hidden';
			cjax_css.style.display = 'none';
		}
		CJAX.set.event(window,'load',CJAX.onStartEvents);
	}
	
	this.cache			=		function() {
		return{
			all : CJAX_CACHE
			,
			add : function(key, value,replace){
					if(typeof replace == 'undefined') var replace = true;
					if(CJAX_CACHE['cache_close'] == 1) {
						return false;
					}
					if((!CJAX_CACHE[key] && replace===true) && value) {
						CJAX_CACHE[key]=value;
					}
				}
			,
			get : function( key ){
					if(CJAX_CACHE[key]) {
						return CJAX_CACHE[key];
					} else {
						return '';
					}
			},
			flush : function(){
				var i, item;
				for(i = CJAX_CACHE.length - 1; i >= 0; i = i - 1){
					item = CJAX_CACHE[i];
					if(delete item[0]){};
					if(item[1].substring(0, 2) != "on"){
						item[1] = "on" + item[1];
					};
					delete item[0][item[1]];
				};
			},
			close : function(){
				CJAX_CACHE['cache_close'] = 1;
			},
			open : function()
			{
				CJAX_CACHE['cache_close'] = 0;
			}
		}
	}();
	
	
	this.set_value		=		function ( buffer ,_value) {
		var element = CJAX.xml('element',buffer);
		if(!CJAX.defined(_value)) {
			var _value = CJAX.decode(CJAX.xml('value',buffer));
		}
		if(!CJAX.is_xml(buffer)) {
			element = buffer;
		}
		var dyna = CJAX.xml("dyna",buffer);
		var select = CJAX.xml("select",buffer);
		
		var obj = CJAX.$( element );
		
		if( !obj ) return false;
		for(x in CJAX.ElementList.get_return()) {
			if(x === obj.type) {
				switch ( CJAX.ElementList.get_return()[x] ) {
					case 'string':
						CJAX.set.value(obj,_value);
						if(dyna) {
                             obj.onclick = function() {
                                if(obj.value==_value) {
                                   obj.value = '';
 
                                }
                            }
						}
						if(select) {
                           obj.focus();
                           obj.select();
                         }
					break;
					case 'boolean':
						var check = (_value == 'true' || _value==1 || _value===true)? true:false;
						obj.checked = check;
					break;
				}
				return true;
			} 
		}
	}
	
	this.ElementList		=		function() {
		var elems = [];
		return {
			get_return : function() {
				elems['text']			= 'string';
				elems['select-one'] 	= 'string';
				elems['select-multiple']= 'string';
				elems['password']		= 'string';
				elems['hidden']			= 'string';
				elems['textarea']		= 'string';
				elems['button']			= 'string';
				elems['submit']			= 'string';
				elems['checkbox']		= 'boolean';
				elems['radio']			= 'boolean';
				return elems;
			},
			types : function () {
				elems[1]='text';
				elems[2]='select-one';
				elems[3]='select-multiple';
				elems[4]='password';
				elems[5]='hidden';
				elems[6]='textarea';
				elems[7]='button';
				elems[8]='submit';
				elems[9]='checkbox';
				elems[10]='radio';
				return elems;				
			}
		}
	
	}();
	
	this.focus			=		function( buffer ) 
	{
		var element = CJAX.is_element(buffer,false);
		if(element){
			element.focus();
		}
	}
	
	this.remove		=		function( buffer ) {
		var element = CJAX.is_element(buffer,false);
		if( !element ) return false;
		element.parentNode.removeChild( element );
	}
	
	this.is_cjax		=		function(buffer) {
		if( !CJAX.xml(this.name,(CJAX.defined(buffer)?buffer:null)) ){ return false; }
		return true;
	}
	
	this.replace_txt		=		function ( clear ) {
		if(typeof clear == 'undefined') var clear = false;
		if (!CJAX.is_cjax()){ return; }
		var myvars = new Array();
		var len;
		var i = 0;
		var value = 1;
		var tags_addition =  18;
		var ar = 0;
		if( clear ) {
			tags_addition = 6+7;
		} else {
			tags_addition = 18;
		}
		
		//this is for use for ajax calls, now needs some testing for "onfly"
		if(!clear) {
		  CJAX.source = CJAX.source.substr(tags_addition,(CJAX.source.length)-tags_addition-6);
		}
		//25 characters for the xml notation +1 for new line, 6 and 7 for the tag length
		//string_len = len+tags_addition;
		while(CJAX.xml(CJAX.name)) {
			value = CJAX.xml(CJAX.name);
			len = value.length;
			if( value ) {
				CJAX.source.replace(value,'');
				CJAX.process( value );
				CJAX.source = CJAX.source.substr(len+7+6);
			}
			i++;
		}
		if( clear ) CJAX.source = '';
		return true;
	}
	
	this.resetDelimeters		=		function(left,right)
	{
		if(CJAX.defined(left) && CJAX.defined(right)) {
			CJAX.left_delimeter = left;
			CJAX.right_delimeter = right;	
		}	else {
			CJAX.left_delimeter = "<";
			CJAX.right_delimeter = ">";
		}
	}
	
	this.get_function		=		function() {
		return CJAX.xml( 'do' );
	}
	
	String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
	}
	String.prototype.ltrim = function() {
	    return this.replace(/^\s+/,"");
	}
	String.prototype.rtrim = function() {
	    return this.replace(/\s+$/,"");
	}
	
	
	String.prototype.xml		=		function(tag,loop) {
		return CJAX.xml(tag,this,loop);
	}
	
	String.prototype.len		=		function()
	{
		return this.length;
	}
	
	String.prototype.array		=		function( tag ) {
		if(!CJAX.defined(tag)) var tag = 'param';
		var vars = CJAX.xml(tag,this,true);
		return vars;
	}
	
	String.prototype.f			=		function(f) {
		if(CJAX.defined(f)){
			return  this.xml( f );
		}
		return  this.xml( 'do' );
	}
	
	String.prototype.vars		=		function(str) {
		return CJAX.vars[str];
	}
	
	String.prototype.loaded		=		function() {
		return CJAX.defined(CJAX.vars['loaded'][this.value])
	}
	
	String.prototype.append		=		function(tag,value) {
		return this.concat(this,'<'+tag+'>'+value+'</'+tag+'>'); 
	}
	
	String.prototype.clear	=	function ( str ){
		this.value = '';
		return true;
	}
	
	String.prototype.trim		=		function( data ) {
	    if ( !data ) return;
	    while (data[0] == ' ' || data[0] == '\n') data = data.substr( 1 ); var l = data.length-1;
	    while (l > 0 && data[l] == ' ' || data[l] == '\n') l--;
	    return this.substring(0, l+1);
	}
	
	this.in_array = function ( subject , array ) {
		//var len = array.length;
		for (x in array) {
			if (x == subject ){ return true;}
		}
		return false;
	}
	
	this.defined		=		function(obj) {
		return (typeof obj!='undefined')? true:false;
	}
	
	this.script		=		function() {
		return {
			loaded : function ( path ,force) {
				if(!CJAX.defined(path)) {
					return false;
				}
				//Loaded by CJAX
				if(!CJAX.defined(force)) {
					return (path.loaded())? true:false;
				} 
				//Loaded on the document
				var scripts = CJAX.elem_docs( 'script' );
				var s;
				if(scripts.length){
					for(var i = 0; i < scripts.length; i++ ){
						s = scripts[i];
						if(s.src==path) return s;
					}
				}
				return false;
				
			},
			load: function(script,f,parameters,secs,bypass) {
				if(!CJAX.defined(parameters)) {
					var parameters = '';
				}
				var type =  CJAX.xml('ctype',parameters);
				if(CJAX.defined(bypass) && bypass) {
					var s = CJAX.script.loaded( script ,'function');
					if ( s )  return s;
				}
				if(typeof secs =='undefined') var secs = 0; else CJAX.seconds = secs;
				CJAX.defined(f);
				
				if(typeof f ==='function') {
					try {
						if ( CJAX.seconds ) {
								setTimeout(f+'("'+parameters+'")',CJAX.seconds*1000);
							} else {
								eval(f+'("'+parameters+'")');
							}
						}
						catch( e ){
							alert('CJAX.script.load() - unabled to load function: '+ f.toUpperCase()+ ' '+e); 
						}
						return true;
				}
				var head = CJAX.elem_docs( 'head' )[0];
				var file_ext = CJAX.get.extension(script);
				if(file_ext=='.css') {
					var s = document.createElement("link");
					s.setAttribute("rel", "stylesheet");
					s.setAttribute("type", "text/css");
					s.setAttribute("href", script);
				}
				else
				{
					var s = document.createElement( 'script' );
					s.type = 'text/javascript';
					s.src= script;
				}

				if ( f )  {
					s.onreadystatechange = function () {
					try{
						if (CJAX.seconds) {
						//alert('f:'+f+ '  seconds: '+CJAX.seconds);
								setTimeout(f+'("'+parameters+'")',CJAX.seconds*1000);
							} else {
								eval(f+'("'+parameters+'")');
							}
						}
						catch( e ){
							if(f =='plugin.class') {
								return true;
							}
							alert('[c001] unabled to load function: '+ f.toUpperCase()+ ' '+e); 
						} 
					}
				   	s.onload =  function () {
	   					try {
								if(CJAX.seconds) {
									setTimeout(f+'("'+parameters+'")',CJAX.seconds*1000);
								} else {
								switch ( type ) {
									case 'extension_system':
									if(parameters)
									eval(f+'.hook("'+parameters+'")');
										break;
									case 'extension_child':
										eval('var x = new '+f+'("'+parameters+'")');
										
										//let go break on purpose
										break;
									default:
										eval(f+'("'+parameters+'")');
								}
							}
						}
						catch( e ){
							if(f =='plugin.class') {
								return true;
							}
							alert('[c002] unabled to load function: '+ f+ ' '+e); 
						}
				   	}
				}
				if(!CJAX.vars['loaded'][script]) {
					CJAX.vars['loaded'][script] = [];
					CJAX.vars['loaded'][script]['function'] = [];
					CJAX.vars['loaded'][script]['function']['src'] = script;
					CJAX.vars['loaded'][script]['function']['function'] = f;
				}
				head.appendChild( s );
				return s;
			},
			reload: function(script,id) {
				if(!CJAX.defined(parameters)) {
					var parameters = '';
				}
				var file_ext = CJAX.get.extension(script);
				if(file_ext=='.css') {
					var s = document.createElement("link");
					s.setAttribute("rel", "stylesheet");
					s.setAttribute("type", "text/css");
					s.setAttribute("href", script);
				} else {
					var s = document.createElement( 'script' );
					s.type = 'text/javascript';
					s.src= script;
					s.id= id;
				}
				var head = CJAX.elem_docs('body')[0];
				head.appendChild( s );
				return s;
			},
			action : function(f,p,s){
				try {
					if ( s ) {
						setTimeout(f+'("'+p+'")',s*1000);
					}else{
						eval(f+'("'+p+'")');
					}
				}
				catch( e ){ alert('unabled to load function: '+ f.toUpperCase()+ ' '+e); }
			}
		}
	}();	
	
	this.process		=		function( buffer ) 
	{
		if(!CJAX.is_cjax()) { alert('no cjax');return false };
		if(typeof buffer =='undefined') var buffer = '';
		CJAX.method = CJAX.get_function();
		if(!CJAX.method) return false;
		var PREFIX = 'CJAX.';
		var f = _FUNCTION = PREFIX+CJAX.method;
		var ext = CJAX.xml('extension',buffer);
		if(CJAX.xml('debug',buffer)) CJAX.debug = true;
	
		if( ext ){
			var f = _FUNCTION = CJAX.method;
			extension.hook( buffer );
		} else {
		    var seconds = CJAX.xml('seconds',buffer);
		    
			if(typeof eval( f ) === 'function' ) {
				try{
					if(seconds){
                       setTimeout(PREFIX+CJAX.method+'("'+buffer+'")',seconds*1000);
						
					} else {
					   eval(PREFIX+CJAX.method+'("'+buffer+'")');
					}
				}
				catch( e ){ alert('unabled to load function: '+ CJAX.method+'();  '+e); }
			}
		}
	}
    
	this.xml		=		function (start , buffer , loop) {
		var source = CJAX.source;
		if(buffer && buffer!=null) source = buffer;
		if(typeof loop =='undefined') var loop = 0;
		if(typeof start=='undefined') return '';
		if(!source || !start) return '';
		var real_var = start;
		var end = CJAX.left_delimeter+'/'+start+CJAX.right_delimeter;
		start = CJAX.left_delimeter+start+CJAX.right_delimeter;
		var loc_start = source.indexOf( start );
		var start_len = start.length;
		var end_len = end.length;
		var loc_end = source.indexOf( end );
		var middle = loc_end - loc_start - end_len +1;
		if (loc_start == -1 || loc_end ==-1) return '';
		var _new_var = source.substr(loc_start+start_len,middle);
		var string_len = loc_start+start_len+_new_var.length+start_len;
		if(loop != 0) {
			var myarr = [];
			var i = 0;
			var value;
			var hold = source;
			string_len = loc_start+start_len+_new_var.length+end_len;
			while(CJAX.xml(real_var,hold) && hold) {
				value = CJAX.xml(real_var,hold);
				hold = hold.substr(loc_start+start_len+value.length+end_len,hold.length);
				myarr[i] = value;
				i++;
			}
			return (myarr)?myarr:'';
		}
		return _new_var;
	}
	
	/**
	*  input will be something like:
	*  <arr><key>1</key><value>value 1</value><key>2</key><value>value 2</value></arr>
	*/
	this.xml_array			=			function(buffer) 
	{
		var array = CJAX.xml('arr',buffer,true);
		var k,v;
		var xml_arr = [];
		
		for(x in array) {
			if(CJAX.is_xml(array[x])) {
				k = CJAX.xml('k',array[x]);
				v = CJAX.xml('v',array[x]);
				xml_arr[k] = v;
			}
		}
		return xml_arr;
	}
	
	/**
	* hide elements
	* usage:
	* CJAX.hide('element_id');
	* or
	* for an group of elements using the same name
	* CJAX.hide('element_name','element_tag'); //element_tag is needed for IE only 
	*
	*/
	this.hide	=	function(buffer,tag,verbose) {
		if( !verbose ) var verbose = true;
		if(!CJAX.defined(tag)) {
			var tag = null;
		}
		if(!CJAX.is_xml(buffer)) {
			var elements = CJAX.getbyname(buffer,tag);
			if(elements) {
				for(var i=0; i < elements.length; i++) {
					element = elements[i];
					element.style.display = 'none';
				}
				return;
			}
		}
		var elem = CJAX.is_element(buffer,verbose); 
		
		if( !elem ) {
			elem = CJAX.xml('element',buffer);
			
			if(elem.substr(1)=='.' || elem.substr(1)=='#') {
				//if we were to get all elements that have a class name
			}
			elem = CJAX.$( elem ); 
		} 
		if( elem ) elem.style.display = 'none'; 
	}
	
	this.getbyname	=    function(name,tag){
        var x=document.getElementsByName(name); 
        
        if(x.length) {
        	return x;
        } else if(x && tag) {
     		var elements = document.getElementsByTagName(tag);
     		var new_elements = [];
     		var element;  
     		var x = 0;
		    for(var i = 0; i < elements.length; i++) {
		    	element = elements[i];
		        if(element.name == name) { 
		           new_elements[x] = element; 
		            x = x+1;
		         } 
		        
		    }
		    return new_elements;
        }
    }
	
	this.show	=	function(buffer,verbose) {
		if( !verbose ) var verbose = true;
		var elem = CJAX.is_element(buffer,false);
		if( !elem ) {
			elem = CJAX.xml('element',buffer);
			elem =  CJAX.$(elem,false);
		}
		if( elem ) { elem.style.display = 'block'; }
	}
	
	this.addCSSRule		=		function(rule,title)  {
		if(CJAX.rule == rule){ return CJAX.getCSSRule( rule ); }
		var styles = document.styleSheets;
		var s;
		var position;
		var create = true;
		var has_length = false;
		for (var i = 0; i < styles.length; i++ ) {
			has_length = true;
			s = styles[i];
			//already exists, no need to create.
			if( s.title == title ){ create = false; break; }
		}
		
		if ( create || !has_length) {
			var s = document.createElement( 'style' );
			s.type = 'text/css';
			s.rel = 'stylesheet';
			s.media = 'screen';
			s.title = title;
			var style_doc = CJAX.elem_docs( "head" )[0];
			if( i> 0 ) {	//there are other stylesheets and we need to get before
				//them, or  else it won't work.
				try{
					//style_doc.firstChild.firstChild;
					style_doc.parentNode.insertBefore(s,style_doc);
				}
				catch( e ){
					/*need to catch exection of Ie will give me an error*/
					alert('caught: '+e);
				}
			} else {	//this is the only styleshee,  awesome!
				style_doc.appendChild( s );
				//style_doc.firstChild.insertBefore(this.style,position);
			}
			//first for FF/ 2 for IE
			s = s.sheet?s.sheet:s.styleSheet;
			
			if (s.addRule) {
				s.addRule(rule, null,0);
			} else {
				s.insertRule(rule+' { }', 0);
			}
		return CJAX.getCSSRule( rule );
		}
	}
	
	this.getCSSRule		=		function( rule ) {
		var rule = rule.toLowerCase();
		var sheets = document.styleSheets;
		if ( !sheets ) { return false; }
		for ( var i=0; i<sheets.length; i++ ) {
			var sheet		=	sheets[i];
			var style_rule	=	sheet.cssRules;
			var style_sheet	=	sheet.rules;
			var cssRule;
			var e			=	0;
			try {
				do {
					this.rule	=	(style_rule)?style_rule[e]:style_sheet[e];e++;
					if (this.rule.selectorText.toLowerCase()==rule){ return this.rule; }
				}
			while (	cssRule	)
			}	catch( e ) { return false; }
		}	
	}

	this.turn		=		function( elem ) {
		if( elem ) {
			if (!elem.type) return false;
			switch ( elem.type ) {
				case 'checkbox':
				case 'radio':
					return true;
				break;
				default:
				return false;
			}
		}
		return false;
	}
	
	this.passvalue		=		function(elem,verbose) {
		if ( typeof verbose=='undefined' ) var verbose = true;
		var obj = CJAX.elem_doc(elem,verbose);
		if ( obj ) {
			switch ( obj.type ) {
				case 'text':
				case 'select-one':
				case 'select-multiple':
				case 'password':
				case 'textarea':
				case 'hidden':
					return escape(obj.value);
				break;
				case 'checkbox':
				return (obj.checked)? 1:0;
				break;
				case 'radio':
					var elements = document.getElementsByTagName("input");
					var element;
					if(elements.length) {
						for(var i = 0; i < elements.length; i++) {
							element = elements[i];
							if(element.type !='radio') continue;
							if(element.checked) {
								return element.value;
							}
						}
					}
					return (obj.checked)? 1:0;
				break;
			}
		}
	}
	
	this.AJAX		=		function() {
		xmlhttp = false;
		
		if (typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest ();
		} else {
			try{
				xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");
			}
			catch ( e ){
				try{
					xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
				}
				catch ( e ){
					xmlhttp = false;
				}
			}
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp = new XMLHttpRequest ();
		}
		return xmlhttp;
	}

	this.create_element		=		function ( buffer ) {
		var elem = CJAX.xml('element',buffer);
		var _parent = CJAX.xml('parent',buffer);
		var _type = CJAX.xml('type',buffer);
		var _class = CJAX.xml('class',buffer);
		var data = CJAX.xml('data',buffer);
		var obj = CJAX.$(elem,false);
		if( obj ) return obj;
		if(_parent =='') return;
		var parent_elem = CJAX.$(_parent);
		if(!parent_elem) return;
		if(_type=='') return;
		var newelem = document.createElement(_type);
		if(_class) newelem.setAttribute('class',_class);
		newelem.setAttribute('id',elem);
		if(data) {
			data =  CJAX.decode(data);
			newelem.innerHTML = data;
		}
		parent_elem.appendChild( newelem );
		return newelem;
	}

	this.intval		=		function( number ) {
		 var ret =  isNaN( number )? false:true;
		 if( ret ) { return number; } else { return 0; } 
	}
	
	this.wait		=		function( buffer ) {
		CJAX.waiting = true;
		CJAX.seconds = CJAX.intval(CJAX.xml('seconds',buffer)) * 1000;
		return true;
	}
	
	this.updateContent		=		function( buffer ) {
		var elem = CJAX.xml('element',buffer);
		var data = unescape(CJAX.xml('data',buffer));
		data = data.replace (/\+/gi, " ");
		var obj = CJAX.$( elem );
		if( obj ) obj.innerHTML = data;
	}
	/**
	* Decodes encoded data that passed by parameter
	* data delivered from php
	**/
	this.decode = function( data , special_chart) {
	 	if( !data ) return '';
	 	var content = data;
	 	if(typeof(special_chart)!='undefined' && special_chart) {
	 		
	 		switch(special_chart) {
		 		case 'sqt':
		 			content = content.replace(/<sqt>/gi,"\"");
		 		break;
		 		case 'sed':
		 			content = content.replace(/<sed>/gi,";");
		 		break;
	 		}
	 		
	 	} else {
			content = content.replace(/<nl>/gi,"\n");
			content = content.replace(/<rt>/gi,"\r");
			content = content.replace(/<qt>/gi,"\"");
			content = content.replace(/<bs>/gi,'\\');
			content = content.replace(/<tb>/gi,"\t");
			content = content.replace(/<ed>/gi,"\;");
		}	
		return content;
	 }
	
	/**
	* return an element object can pass an string as id or an object
	**/
	this.is_element			=			function(element,verbose) {
		if(!element) {
			return;
		}
		if( typeof verbose === 'undefined') { var verbose = true; }
		if( verbose ) if( !element ){CJAX.alert('invalid input on function: '+_FUNCTION+' :  not an element ');return;}
		var _element;
		var type = (typeof element);
		if( type.indexOf( 'object' ) != -1) return element;
		_element = CJAX.$(element,verbose);
		if(_element) return _element;
		_element = CJAX.xml('element',element);
		if(_element) return CJAX.$(_element,false);
		return;
	}
	
	/**
	* update an element on the page
	**/
	this.update		=		function(buffer,data) {
		var element = CJAX.is_element(buffer,false);
		if( !element ) return false;
		if( !data ) var data = CJAX.xml('data',buffer);
		data = CJAX.decode( data ); 
		element.innerHTML = data;
	}
	
	/**
	* load external script into page head
	*/
	this.load_script = function ( params ) {
		if(typeof params =='undefined' || !params) return false;
		var url = CJAX.xml('script',params);
		if(!url) {
			url = params;
		}
		if(CJAX.strpos(url,'__domain__') !==false) {
			url = url.replace('__domain__',CJAX.get.dirname(document.baseURI));
		}
		if( !url.loaded() ) {
			var s = CJAX.script.load( url );
		}
	}
	
	// http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
	this.strpos		=		function(haystack, needle, offset)
	{
		if(!CJAX.defined(offset)) {
			var offset = 0;
		}
		var i = haystack.indexOf( needle, offset ); // returns -1
		return i >= 0 ? i : false;
	}
	
	this.applyClassToType		=		function() {
		var tag = CJAX.xml( 'tag' );
		var type = CJAX.xml( 'type' );
		var _class = CJAX.xml( 'class' );
		var elems = CJAX.elem_docs((tag? tag:'input'));
		if( !elems )return false;
		if( !type ) return false;
		if(!_class) return false;
		var elem;
		for ( var c = 0; c < elems.length; c++){
			elem = elems[c];
			if(elem.type == type){
				elem.className = _class;
			}
		}
	}
	
	this.applyClass		=		function(buffer) {
		var elems = CJAX.elem_docs(CJAX.xml('elem_tag',buffer));
		var _class = CJAX.xml( 'class',buffer );
		if(elems.length){
			if(_class){
				for(var c = 0; c < elems.length; c++){
					elems[c].className = _class;
				}
			}
		}
	}
	
	/*
	* displays an alert message with passed data
	*/
	this.alert		=		function ( buffer ) {
		var msg = CJAX.xml('msg',buffer);
		smg = CJAX.decode( msg );
		alert( smg );
	}
	
	/**
	* redirected to specified location
	*/
	this.location		=		function( buffer ) {
		var destination = CJAX.xml('url',buffer);
		window.location = destination;	
	}
	
	function var_dump( obj ) {
		if(typeof obj == "object") {
			return "Type: "+typeof( obj )+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
		} else {
			return "Type: "+typeof( obj )+"\nValue: "+obj;
		}
	}
	
	this.getSelectedRadio		=		function( buttonGroup ) {
	   if (buttonGroup[0]) {
	      for (var i=0; i<buttonGroup.length; i++) {
	         if (buttonGroup[i].checked) {
	            return i
	         }
	      }
	   } else {
	      if (buttonGroup.checked) { return 0; } 
	   }
	   return -1;
	} 
	
	this.getSelectedRadioValue		=		function( buttonGroup ) {
	   var i = CJAX.getSelectedRadio( buttonGroup );
	   if (i == -1) {
	      return "";
	   } else {
	      if (buttonGroup[i]) {
	         return buttonGroup[i].value;
	      } else {
	         return buttonGroup.value;
	      }
	   }
	}
	
	/*
	* checks to see if specific data is an array
	*/
	this.is_array		=		function( element ) {
		if(element.length) return true;
		return false;
	}
	
	this.is_xml						=			function(data)
	{
		if(typeof data !='string') {
			return false;
		}
		if(data.indexOf(CJAX.left_delimeter)!=-1 && data.indexOf(CJAX.right_delimeter)!=-1) {
			return true;
		}
		return false;
	}

	this.form_get_elements_url		=		function( frm_object ) {
		var frm_url = '';
		var elem;
		var value;
		var c = 0;
		var form =  CJAX.is_element(frm_object).getElementsByTagName("*");
		for(var n = 0; n < form.length; n++){
			if(form[n].id =='undefined' && form[n].name =='undefined') continue;
			c++;
			elem = form[n];
			elem_id = elem.id;
			elem_type = elem.type;
			elem_value = elem.value;
			elem_len = elem.length;
			elem_id = elem.id;
			if((elem.id && elem.name !='') || (elem.id == 'undefined' && elem.name !='')){
				elem_id = elem.name; 
			}
			switch ( elem.type ) {
				case 'checkbox':
					value = ((elem.checked)? 1:0);
				break;
						case 'text':
						case 'select-one':
						case 'textarea':
							value = elem.value;
				break;
				case 'radio':
				
					if(CJAX.getSelectedRadio( elem ) === -1)continue;
					
					value = CJAX.getSelectedRadioValue( elem );
					break;
				default:
					value = encodeURI(elem.value);
			}
			if(value !='undefined' && elem_id) frm_url += "&"+elem_id + "="+ value;
		}
		return frm_url;
	}

	this.exe_form		=		function( params ) {
		params = CJAX.decode(params);
		var destino = CJAX.xml('url',params);
		var frm = CJAX.xml('form',params);
		var container = CJAX.xml('container',params);
		var text = CJAX.xml('text',params);
		if( !text ) text = 'Loading...';
		var image = CJAX.xml('image',params);
		var mode  = CJAX.xml('method',params);
		if( !mode ) mode = 'get';
		var file_form = null;
		var frame = null;
		var files = false;
		
		if(frm != '') {
			var url ='';
			var elem_value = '';
			var is_my_radio = new Array( 10 );
			var splitter;
			var assign = '=';
			form = document.forms[frm]
			if( !form ) {
				var url = CJAX.form_get_elements_url( frm );
				if( !url ){ CJAX.alert('CJAX: Please specify a form name'); return false; }
			} else {
				var elems =  form.elements? form.elements: elems;
				var form_len = elems.length;
				for (var n=0; n < form_len; n++) {
					splitter = '&';
					elem  = elems[n];
					elem_id = elem.id;
					elem_type = elem.type;
					elem_name =  elem.name;
					elem_value = elem.value;
					elem_len = elem.length;
					if(!elem_type)continue;
					if(elem_type=='file') {
						files = true;
					}
					if(elem_id && elem_name)elem_id = elem_name;
					if(!elem_id && elem_name)elem_id = elem_name;
					switch ( elem_type ) {
						case 'checkbox':
							elem_value = ((elem.checked)? 1:0);
						break;
						case 'text':
						case 'select-one':
						case 'textarea':
							assign='=';
							elem_value = elem.value;
						break;
						case 'radio':					
							if(CJAX.getSelectedRadio( elem ) != -1) {
								if(CJAX.getSelectedRadioValue( elem )) 
								elem_value = CJAX.getSelectedRadioValue( elem ); assign='=';
							}else{
								splitter =''; elem_id =''; elem_value =''; assign='';
							}
							break;
						default:
							elem_value = elem.value;
					}
					url += splitter;
					url += elem_id + assign + encodeURI(elem_value);
					assign = '=';
				}
				destino += url;
				if(files) {
					iframe = CJAX.create.frame('files');
					iframe.style.position = 'absolute';
					if(!CJAX.debug) {  
						iframe.style.display = 'none';
					}
					document.body.appendChild(iframe);
					form.action = destino;
					form.target = 'files';
					form.submit();
				}
			}
	  	}

		if ( container == 'REDIRECT' ){
			window.location = destino;
			return;
		}
		if( container ){
			container = CJAX.$( container );
			if( !container )return false;
		}
		if(!CJAX.HTTP_REQUEST_INSTANCE) CJAX.HTTP_REQUEST_INSTANCE = CJAX.AJAX();
		
		if(destino.indexOf('&') != -1) {
		  var ms=+new Date().getTime();
		  destino += "&cjax="+ms;
		}
		if (mode.toLowerCase()  == "get") {
			CJAX.HTTP_REQUEST_INSTANCE.open (mode, destino);   //ms="+new Date().getTime());			
		} else {
			if (CJAX.HTTP_REQUEST_INSTANCE.overrideMimeType) {
				CJAX.HTTP_REQUEST_INSTANCE.overrideMimeType('text/xml');
			}
			CJAX.HTTP_REQUEST_INSTANCE.open ('POST', destino,true);
			CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Content-length", destino.length);
			if(destino.length > 1500) {
				CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Connection", "Keep-Alive");
			} else {
				CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Connection", "Closed");
			}
		}
		CJAX.HTTP_REQUEST_INSTANCE.onreadystatechange = function () {
			if(CJAX.HTTP_REQUEST_INSTANCE.readyState <= 4) {				
				if (image == '') {
		 			image = "<img src='cjax/core/images/loading.gif'/>";
				} else {
					image = "<img src='"+image+"'/>" ;
				}
				if( container ) container.innerHTML = "<span>"+image+"&nbsp;"+text+"</span>";  
			}		
			if (CJAX.HTTP_REQUEST_INSTANCE.readyState == 4 && CJAX.HTTP_REQUEST_INSTANCE.status == 200) {
				var txt =  unescape(CJAX.HTTP_REQUEST_INSTANCE.responseText);
				CJAX.source = txt;
				CJAX.replace_txt();
				if( container ) container.innerHTML = txt;	
	     		if (CJAX.debug) CJAX.alert(container.innerHTML);
			}else if (CJAX.HTTP_REQUEST_INSTANCE.readyState == 4 && CJAX.HTTP_REQUEST_INSTANCE.status == 404) {
				container.innerHTML = '<div>Error: File not found '+destino+'</div>'; 					
			}
		}
		CJAX.HTTP_REQUEST_INSTANCE.send ( null );
	}
	
	this.$					=		function(e,v) {
		if(!e) {
			return;
		}
		return CJAX.elem_doc(e,v);
	}
	
	this.elem_doc		=		function(id_obj,verbose) {
		var type = (typeof elem);
		if( typeof verbose == 'undefined' && CJAX.debug) { verbose = true; }
		if( type.indexOf( 'object' ) == -1) {var elem = document.getElementById(id_obj);}
		if(typeof id_obj == 'undefined' || id_obj===null) {
			if( verbose ) CJAX.alert('Element not found'); 
		 	return false;
		}
		
		if( !elem ){
			if( verbose ) CJAX.alert('CJAX: Element "'+id_obj+'" not found on document');
			return false;
		}
		elem.left = (elem.style.left)?elem.style.left:elem.left;
		elem.width = elem.offsetWidth;
		elem.height = elem.offsetHeight;
		return elem;
	}
	
	this.elem_docs		=		function(id_obj,verbose) {
		if(typeof verbose =='undefined') verbose = true;	
		var obj = document.getElementsByTagName(id_obj);
		if( !obj ) {
			if( verbose ) CJAX.alert('CJAX: Element '+id_obj+' not found on document');
			return;
		}			
		return obj;
	}
	
	this.getY		=		function () {
		 var scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	  }
	  return scrOfY;
	}
		
	this.getX 	=	 function() {
		var scrOfX = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape 
			compliantscrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM 
			compliantscrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant 
			modescrOfX = document.documentElement.scrollLeft;}return scrOfX;
	} 
	
	function __construct() {
		if(CJAX.script.load(__base__+"/components/extensions.js")) CJAX.COMPONENTS['extensions'] = 1;
		CJAX.script.load(__base__+'/core/classes/cjax.js.php');
		//not meant to be a formatted, but it can be used as a helper to display
		//well formatted messages
		CJAX.script.load(__base__+'/core/css/cjax.css');
	}
	
	    
    this.unserialize		=		function(data) {
        // http://kevin.vanzonneveld.net
        // +     original by: Arpad Ray (mailto:arpad@php.net)
        // +     improved by: Pedro Tainha (http://www.pedrotainha.com)
        // +     bugfixed by: dptr1988
        // +      revised by: d3x
        // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +      input by: Brett Zamir
        // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // %            note: We feel the main purpose of this function should be to ease the transport of data between php & js
        // %            note: Aiming for PHP-compatibility, we have to translate objects to arrays 
        // *       example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');
        // *       returns 1: ['Kevin', 'van', 'Zonneveld']
        // *       example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');
        // *       returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}
        
        var error = function (type, msg, filename, line){throw new window[type](msg, filename, line);};
        var read_until = function (data, offset, stopchr){
            var buf = [];
            var chr = data.slice(offset, offset + 1);
            var i = 2;
            while (chr != stopchr) {
                if ((i+offset) > data.length) {
                    error('Error', 'Invalid');
                }
                buf.push(chr);
                chr = data.slice(offset + (i - 1),offset + i);
                i += 1;
            }
            return [buf.length, buf.join('')];
        };
        var read_chrs = function (data, offset, length){
            var buf;
            
            buf = [];
            for(var i = 0;i < length;i++){
                var chr = data.slice(offset + (i - 1),offset + i);
                buf.push(chr);
            }
            return [buf.length, buf.join('')];
        };
        var _unserialize = function (data, offset){
            var readdata;
            var readData;
            var chrs = 0;
            var ccount;
            var stringlength;
            var keyandchrs;
            var keys;
     
            if(!offset) offset = 0;
            var dtype = (data.slice(offset, offset + 1)).toLowerCase();
            
            var dataoffset = offset + 2;
            var typeconvert = new Function('x', 'return x');
            
            switch(dtype){
                case "i":
                    typeconvert = new Function('x', 'return parseInt(x)');
                    readData = read_until(data, dataoffset, ';');
                    chrs = readData[0];
                    readdata = readData[1];
                    dataoffset += chrs + 1;
                break;
                case "b":
                    typeconvert = new Function('x', 'return (parseInt(x) == 1)');
                    readData = read_until(data, dataoffset, ';');
                    chrs = readData[0];
                    readdata = readData[1];
                    dataoffset += chrs + 1;
                break;
                case "d":
                    typeconvert = new Function('x', 'return parseFloat(x)');
                    readData = read_until(data, dataoffset, ';');
                    chrs = readData[0];
                    readdata = readData[1];
                    dataoffset += chrs + 1;
                break;
                case "n":
                    readdata = null;
                break;
                case "s":
                    ccount = read_until(data, dataoffset, ':');
                    chrs = ccount[0];
                    stringlength = ccount[1];
                    dataoffset += chrs + 2;
                    
                    readData = read_chrs(data, dataoffset+1, parseInt(stringlength));
                    chrs = readData[0];
                    readdata = readData[1];
                    dataoffset += chrs + 2;
                    if(chrs != parseInt(stringlength) && chrs != readdata.length){
                        error('SyntaxError', 'String length mismatch');
                    }
                break;
                case "a":
                    readdata = {};
                    
                    keyandchrs = read_until(data, dataoffset, ':');
                    chrs = keyandchrs[0];
                    keys = keyandchrs[1];
                    dataoffset += chrs + 2;
                    
                    for(var i = 0;i < parseInt(keys);i++){
                        var kprops = _unserialize(data, dataoffset);
                        var kchrs = kprops[1];
                        var key = kprops[2];
                        dataoffset += kchrs;
                        
                        var vprops = _unserialize(data, dataoffset);
                        var vchrs = vprops[1];
                        var value = vprops[2];
                        dataoffset += vchrs;
                        
                        readdata[key] = value;
                    }
                    
                    dataoffset += 1;
                break;
                default:
                    error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
                break;
            }
            return [dtype, dataoffset - offset, typeconvert(readdata)];
        };
        return _unserialize(data, 0)[2];
    }
    
    	this.exe_html		=		function( params ) {
		params = CJAX.decode(params);
		var msg = null;
		CJAX.resetDelimeters("[","]");
		var destino = CJAX.xml('url',params);
		var parts = destino.split("&");
		var part;
		if(parts) {
			for(x in parts) {
				if(!part) {
					part = CJAX._value(parts[x]);
				} else {
					part += "&"+CJAX._value(parts[x]);
				}
			}
		}
		if(part) {
			destino = part;
		}
		var text = CJAX.xml('text',params);
		if( !text ) text = 'Loading...';
		var mode  = (CJAX.xml('mode',params)? CJAX.xml('mode',params):'get');
		var image = CJAX.xml('image',params);
		var element =  CJAX.xml('element',params);
		CJAX.resetDelimeters();
		
		if (element == "REDIRECT"){
			window.location = destino;
			return;
		}
		if( element ){
			var element = CJAX.is_element( element );
			if( !element ) return false;
		}
		CJAX.HTTP_REQUEST_INSTANCE = this.AJAX ();
		 
		if(destino.indexOf('&') != -1) {
			var ms=+new Date().getTime();
			destino += "&cjax="+ms;
		}
		
		if (mode.toLowerCase()  == "get") {
			CJAX.HTTP_REQUEST_INSTANCE.open (mode, destino); //ms="+new Date().getTime());
		} else {
			if (CJAX.HTTP_REQUEST_INSTANCE.overrideMimeType) {
				//http_request.overrideMimeType('text/xml');
				CJAX.HTTP_REQUEST_INSTANCE.overrideMimeType('text/html');
			}
			CJAX.HTTP_REQUEST_INSTANCE.open (mode, destino,true);
			CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Content-length", destino.length);
			CJAX.HTTP_REQUEST_INSTANCE.setRequestHeader("Connection", "Keep-Alive");
		}
		
		CJAX.HTTP_REQUEST_INSTANCE.onreadystatechange		=		function() {
			if(CJAX.HTTP_REQUEST_INSTANCE.readyState < 4) {
				//document.body.style.cursor = 'wait';	
				if ( !image )image = "cjax/core/images/loading.gif'";
				if( element ) element.innerHTML = "<span><img src='"+image+"/>&nbsp;"+text+"</div>";
			}
			try{
				if (CJAX.HTTP_REQUEST_INSTANCE.readyState == 4 && CJAX.HTTP_REQUEST_INSTANCE.status == 200) {
					var txt =  unescape(CJAX.HTTP_REQUEST_INSTANCE.responseText);
					msg = CJAX.source = txt;
					CJAX.replace_txt();
				
					if( element ){
			      		element.innerHTML = txt;
			      	}
					if (CJAX.debug) {
						var win = window.open('<pre>'+txt+'</pre>', "","width=500","height=400");
					}
				}
				else if (CJAX.HTTP_REQUEST_INSTANCE.readyState == 4 && CJAX.HTTP_REQUEST_INSTANCE.status == 404) {
					
					var msg = 'CJAX Error: File not found '+destino;
					if( element ) {
						if(!element.type) { alert( msg ); return false; }
						element.innerHTML = msg; 
					}		
				}
			}
			catch( err )
			{ alert('CJAX: Error - '+err.description); }
		}
		CJAX.HTTP_REQUEST_INSTANCE.send ( null );
		return CJAX.source;
	}
	
	/**
	* Generates a autocomplete dropdown for a text field by specifiying the text field id and an array with the posible matches. 
	* It can only be called from php.
	*  
	* example:
	*
	* $CJAX->action(null, array('keyup' => $CJAX->auto_complete("text_field_id",array('text 1','text 2','text 3',''))));
	*/
	this.auto_complete		=		function(buffer)
	{
		var array = [];
		if(CJAX_CACHE['xml_array']) {
			array = CJAX_CACHE['xml_array'];
		} else {
		 	array = CJAX.xml('elements',buffer);
		 	CJAX_CACHE['xml_array'] = array = CJAX.xml_array(array);
		 }
		 
		var element = CJAX.$(CJAX.xml('element',buffer));
		if(!element) {
			return false;
		}
		if(element.getAttribute('autocomplete') !='off') {
			element.setAttribute("autocomplete", 'off');
		}
		var position = CJAX.get.position(element);
		var div = CJAX.$('auto_complete_div');

		//position[4] = position[4]+element.offmarginLeft;
		
		//alert(position[4]);
		element.style.position = 'relative';
		if(!div) {
			div = CJAX.create.div('auto_complete_div');
			with (div.style) {
				position = 'absolute'; 
				minWidth = element.offsetWidth-3+'px';
				maxHeight = '250px';
				overflow = 'auto'; 
				borderStyle='solid';
				borderWidth = '1px';
				borderColor = '#317082';
				backgroundColor ='#FFFFFF';
				fontSize = '0.9em';
				top = position[0]+'px';
				left = element.offsetLeft+"px";
				paddingLeft = '2px';
				//marginLeft =  (element.offsetWidth / 2);//position[4]+'px';
				zIndex = '99';
				display = 'block';
			}
			
			/*
			pageYOffset ) == 'number' ) {
		//Netscape 
			compliantscrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM 
			compliantscrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant 
			modescrOfX = document.documentElement.scrollLeft;}return scrOfX;
			
			*/
			element.onkeydown = function(e) {
				var keycode;
				if (window.event) keycode = window.event.keyCode;
				else if (e) keycode = e.which;
				
				var next_child = last_child = null;
					
				if(keycode==40) {
					//scroll down
					var children = div.childNodes;
					for (var i = 0; i < children.length; i++) {
						next_child = children[i].nextSibling;
						if(CJAX_CACHE['current_child']) {
							last_child = CJAX_CACHE['current_child'];
							last_child.style.backgroundColor = '#FFFFFF';
							last_child.style.color ='#000000';
							next_child = CJAX_CACHE['current_child'].nextSibling
						}
						if(!next_child) {
							next_child = children.firstChild;
							if(!next_child) {
								break;
							}
						}
						next_child.focus();
						next_child.style.backgroundColor = '#316AC5';
						next_child.style.color ='#FFFFFF';
						CJAX_CACHE['current_child']  = next_child;
						
						CJAX_CACHE['next_child_value'] = next_child.innerHTML;
						break;
					}
					if(next_child) {
						div.scrollTop = next_child.offsetTop;
					}
					//div.scrollTop += 10
					CJAX_CACHE['break'] = true;
				} else if(keycode == 38) {
					var children = div.childNodes;
				
					for (var i = 0; i < children.length; i++) {
						next_child = children[i].previousSibling;
						if(!next_child) {
							next_child = children.firstChild;
							if(!next_child) {
								next_child = CJAX_CACHE['current_child'];
								if(!next_child) {
									break;
								}
							} else {
								CJAX_CACHE['current_child'] = next_child;
							}
						}
						if(CJAX_CACHE['current_child']) {
							last_child = CJAX_CACHE['current_child'];
							last_child.style.backgroundColor = '#FFFFFF';
							last_child.style.color ='#000000';
							next_child = CJAX_CACHE['current_child'].previousSibling
						}
						if(!next_child) {
							CJAX_CACHE['current_child'] = children.firstChild;
							break;
						}
						next_child.focus();
						next_child.style.backgroundColor = '#316AC5';
						next_child.style.color ='#FFFFFF';
						CJAX_CACHE['current_child']  = next_child;
						CJAX_CACHE['next_child_value']  = nex_child.innerHTLM;
						break;
					}
					if(next_child) {
						div.scrollTop = next_child.offsetTop;
					}
				} else if(keycode == 13) {
					if(CJAX_CACHE['next_child_value']) {
						this.value = CJAX_CACHE['next_child_value'];
					}
					
					return false;
				}
				if(CJAX_CACHE['last_child']) {
					CJAX_CACHE['last_child'].style.backgroundColor = "#FFFFFF";
					CJAX_CACHE['last_child'].style.color ='#000000';
				}
				CJAX_CACHE['break'] = false;
			}
			
			element.onblur = function(e) {
				setTimeout(function() {div.style.display ='none';},150);
			}
			
			//element.parentNode.appendChild(div);
			insertAfter(element.parentNode,div,element);
		}
		div.style.display = 'block';
		if(CJAX_CACHE['break']) {
			//return true;
		}
		
		function insertAfter(parent, node, referenceNode) {
			var ref = null;
			if(referenceNode.nextSibling) {
				ref = referenceNode.nextSibling;
			}
			if(ref.nextSibling) {
				ref = ref.nextSibling;
			}
		  parent.insertBefore(node, ref);
		}
		
		var child = [];
		var last_child = null;
		var string,string2 = null;
		var bool_empty = true;
		for(x in array) {
			child[x] = CJAX.create.div('auto_complete_div_child'+x);
			child[x].style.display = 'block';
			string = child[x].innerHTML.toLowerCase();
			string2 = element.value.toLowerCase();
			

			if(string.length > 1 && string.indexOf(string2) == -1) {
				child[x].style.display = 'none';
				continue;
			}
			bool_empty = false;
			
			with (child[x].style) {
				marginLeft = '1px';
				marginRight = '1px';
				marginTop = '1px';
				marginBottom = '1px';
				paddingLeft = '1px';
				paddingRight = '1px';
				paddingTop = '1px';
				paddingBottom = '1px';
				cursor = 'pointer';
				fontSize = '0.9em';
			}
			child[x].innerHTML = array[x];
			child[x].onmouseover = function(e) {
				this.style.backgroundColor = '#316AC5';
				this.style.color ='#FFFFFF';
				
				if(CJAX_CACHE['last_child']) {
					CJAX_CACHE['last_child'].style.backgroundColor = "#FFFFFF";
					CJAX_CACHE['last_child'].style.color ='#000000';
				}
				if(CJAX_CACHE['current_child']) {
					CJAX_CACHE['current_child'].style.backgroundColor = "#FFFFFF";
					CJAX_CACHE['current_child'].style.color ='#000000';
				}
				CJAX_CACHE['last_child'] = this;
			}
			
			child[x].onblur	=	function(e)
			{
				CJAX_CACHE['focus_element'] = child[x];
				element.value = this.innerHTML;
				alert('gets');
			}
			
			child[x].onclick = function (e) {
				element.value = this.innerHTML;
				//div.style.display = 'none';
				//CJAX_CACHE['current_child'] = this;
			}
			div.appendChild(child[x]);
			
		}
		if(bool_empty) {
			div.style.display = 'none';
		}
	}
	
	function Browser()
	{
	  var ua, s, i;
	
	  this.isIE    = false;
	  this.isNS    = false;
	  this.version = null;
	
	  ua = navigator.userAgent;
	
	  s = "MSIE";
	  if ((i = ua.indexOf(s)) >= 0) {
	    this.isIE = true;
	    this.version = parseFloat(ua.substr(i + s.length));
	    return;
	  }
	
	  s = "Netscape6/";
	  if ((i = ua.indexOf(s)) >= 0) {
	    this.isNS = true;
	    this.version = parseFloat(ua.substr(i + s.length));
	    return;
	  }
	
	  // Treat any other "Gecko" browser as NS 6.1.
	
	  s = "Gecko";
	  if ((i = ua.indexOf(s)) >= 0) {
	    this.isNS = true;
	    this.version = 6.1;
	    return;
	  }
	}

	var browser = new Browser();
	var dragObj = new Object();
	dragObj.zIndex = 0;	
	
	this.drag		=		function(event, id)
	{
	  var el;
	  var x, y;
	
	  // If an element id was given, find it. Otherwise use the element being
	  // clicked on.
	
	  if (id)
	    dragObj.elNode = document.getElementById(id);
	  else {
	    if (browser.isIE)
	      dragObj.elNode = window.event.srcElement;
	    if (browser.isNS)
	      dragObj.elNode = event.target;
	
	    // If this is a text node, use its parent element.
	
	    if (dragObj.elNode.nodeType == 3)
	      dragObj.elNode = dragObj.elNode.parentNode;
	  }
		dragObj.elNode.style.pointer = 'move';
	  // Get cursor position with respect to the page.
	
	  if (browser.isIE) {
	    x = window.event.clientX + document.documentElement.scrollLeft
	      + document.body.scrollLeft;
	    y = window.event.clientY + document.documentElement.scrollTop
	      + document.body.scrollTop;
	  }
	  if (browser.isNS) {
	    x = event.clientX + window.scrollX;
	    y = event.clientY + window.scrollY;
	  }
	
	  // Save starting positions of cursor and element.
	
	  dragObj.cursorStartX = x;
	  dragObj.cursorStartY = y;
	  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
	  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);
	
	  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
	  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;
	
	  // Update element's z-index.
	
	  dragObj.elNode.style.zIndex = ++dragObj.zIndex;
	
	  // Capture mousemove and mouseup events on the page.
	
	  if (browser.isIE) {
	    document.attachEvent("onmousemove", CJAX._dragGo);
	    document.attachEvent("onmouseup",   CJAX._dragStop);
	    window.event.cancelBubble = true;
	    window.event.returnValue = false;
	  }
	  if (browser.isNS) {
	    document.addEventListener("mousemove", CJAX._dragGo,   true);
	    document.addEventListener("mouseup",   CJAX._dragStop, true);
	    event.preventDefault();
	  }
	}
	
	
	this._dragGo 	= 		function(event) 
	{
	  var x, y;
	
	  // Get cursor position with respect to the page.
	
	  if (browser.isIE) {
	    x = window.event.clientX + document.documentElement.scrollLeft
	      + document.body.scrollLeft;
	    y = window.event.clientY + document.documentElement.scrollTop
	      + document.body.scrollTop;
	  }
	  if (browser.isNS) {
	    x = event.clientX + window.scrollX;
	    y = event.clientY + window.scrollY;
	  }
	
	  // Move drag element by the same amount the cursor has moved.
	
	  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
	  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
	
	  if (browser.isIE) {
	    window.event.cancelBubble = true;
	    window.event.returnValue = false;
	  }
	  if (browser.isNS)
	    event.preventDefault();
	}
	
	this._dragStop	=	 function(event) 
	{
	  // Stop capturing mousemove and mouseup events.
	
	  if (browser.isIE) {
	    document.detachEvent("onmousemove", CJAX._dragGo);
	    document.detachEvent("onmouseup",   CJAX._dragStop);
	  }
	  if (browser.isNS) {
	    document.removeEventListener("mousemove", CJAX._dragGo,   true);
	    document.removeEventListener("mouseup",   CJAX._dragStop, true);
	  }
	}
	
}